<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionController::ForceSSL::ClassMethods</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionController::ForceSSL::ClassMethods 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_controller/metal/force_ssl_rb.html">actionpack/lib/action_controller/metal/force_ssl.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-force_ssl">force_ssl</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-force_ssl">
            
              <b>force_ssl</b>(options = {})
            
            <a href="ClassMethods.html#method-i-force_ssl" name="method-i-force_ssl" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Force the request to this particular controller or specified actions to be
under HTTPS protocol.</p>

<p>If you need to disable this for any reason (e.g. development) then you can
use an <code>:if</code> or <code>:unless</code> condition.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">AccountsController</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ApplicationController</span>
  <span class="ruby-identifier">force_ssl</span> <span class="ruby-keyword">if</span><span class="ruby-operator">:</span> :<span class="ruby-identifier">ssl_configured?</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier">ssl_configured?</span>
    <span class="ruby-operator">!</span><span class="ruby-constant">Rails</span>.<span class="ruby-identifier">env</span>.<span class="ruby-identifier">development?</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<h4 id="method-i-force_ssl-label-URL+Options">URL Options</h4>

<p>You can pass any of the following options to affect the redirect url</p>
<ul><li>
<p><code>host</code>       - Redirect to a different host name</p>
</li><li>
<p><code>subdomain</code>  - Redirect to a different subdomain</p>
</li><li>
<p><code>domain</code>     - Redirect to a different domain</p>
</li><li>
<p><code>port</code>       - Redirect to a non-standard port</p>
</li><li>
<p><code>path</code>       - Redirect to a different path</p>
</li></ul>

<h4 id="method-i-force_ssl-label-Redirect+Options">Redirect Options</h4>

<p>You can pass any of the following options to affect the redirect status and
response</p>
<ul><li>
<p><code>status</code>     - Redirect with a custom status (default is 301
Moved Permanently)</p>
</li><li>
<p><code>flash</code>      - Set a flash message when redirecting</p>
</li><li>
<p><code>alert</code>      - Set a alert message when redirecting</p>
</li><li>
<p><code>notice</code>     - Set a notice message when redirecting</p>
</li></ul>

<h4 id="method-i-force_ssl-label-Action+Options">Action Options</h4>

<p>You can pass any of the following options to affect the before_action
callback</p>
<ul><li>
<p><code>only</code>       - The callback should be run only for this action</p>
</li><li>
<p><code>except</code>     - The callback should be run for all actions except
this action</p>
</li><li>
<p><code>if</code>         - A symbol naming an instance method or a proc; the
callback</p>

<pre>will be called only when it returns a true value.</pre>
</li><li>
<p><code>unless</code>     - A symbol naming an instance method or a proc; the
callback</p>

<pre>will be called only when it returns a false value.</pre>
</li></ul>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-force_ssl_source')" id="l_method-i-force_ssl_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ab08519b1aed46dbd4b3e13932bbaddfe42d8315/actionpack/lib/action_controller/metal/force_ssl.rb#L62" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-force_ssl_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/force_ssl.rb, line 62</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">force_ssl</span>(<span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">action_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(*<span class="ruby-constant">ACTION_OPTIONS</span>)
  <span class="ruby-identifier">redirect_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except</span>(*<span class="ruby-constant">ACTION_OPTIONS</span>)
  <span class="ruby-identifier">before_action</span>(<span class="ruby-identifier">action_options</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">force_ssl_redirect</span>(<span class="ruby-identifier">redirect_options</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    